home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / os2tools / bnklysrc / timer.c < prev    next >
C/C++ Source or Header  |  1989-01-01  |  7KB  |  179 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software <no-Inc>                   */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          No-Cost<no-tm> Software.                       */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  Copyright (C) 1987, 1988, 1989 by Robert Hartman and Vincent Perriello  */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*                 This module was written by Bob Hartman                   */
  14. /*               with some hacking done by Vince Perriello                  */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*                       BinkleyTerm timer routines                         */
  18. /*                                                                          */
  19. /*                                                                          */
  20. /*    For complete  details  of the licensing restrictions, please refer    */
  21. /*    to the License  agreement,  which  is published in its entirety in    */
  22. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.210.    */
  23. /*                                                                          */
  24. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  25. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  26. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  27. /*    NOT HAVE THESE FILES,  YOU SHOULD  IMMEDIATELY CONTACT THE AUTHORS    */
  28. /*    AT THE  ADDRESSES LISTED BELOW.  IN NO EVENT SHOULD YOU PROCEED TO    */
  29. /*    USE   THIS  FILE  WITHOUT  HAVING   ACCEPTED  THE  TERMS  OF   THE    */
  30. /*    BINKLEYTERM  LICENSING AGREEMENT,  OR SUCH OTHER  AGREEMENT AS YOU    */
  31. /*    ARE ABLE TO REACH WITH THE AUTHORS.                                   */
  32. /*                                                                          */
  33. /*                                                                          */
  34. /*    The Authors can be reached at the following addresses:                */
  35. /*                                                                          */
  36. /*    Robert C. Hartman                      Vincent E. Perriello           */
  37. /*    Spark Software                         VEP Software                   */
  38. /*    427-3 Amherst Street                   111 Carroll Street             */
  39. /*    CS2032, Suite 232                      Naugatuck, CT 06770            */
  40. /*    Nashua, NH 03061                                                      */
  41. /*                                                                          */
  42. /*    FidoNet 1:132/101                      FidoNet 1:141/491              */
  43. /*    Data    (603) 888-8179                 Data    (203) 729-7569         */
  44. /*                                                                          */
  45. /*    Please feel free to contact us at any time to share your comments     */
  46. /*    about our software and/or licensing policies.                         */
  47. /*                                                                          */
  48. /*--------------------------------------------------------------------------*/
  49.  
  50. /*
  51.   
  52.     This file contains routines to implement a simple multiple
  53.     alarm system.  The routines allow setting any number of alarms,
  54.     and then checking if any one of them has expired.  It also allows
  55.     adding time to an alarm.
  56. */
  57.  
  58.  
  59. /*
  60.  * $Log$
  61.  */
  62.  
  63.  
  64. #include "com.h"
  65. #include "xfer.h"
  66. #include "zmodem.h"
  67. #include "keybd.h"
  68. #include "sbuf.h"
  69. #include "sched.h"
  70. #include "externs.h"
  71. #include "prototyp.h"
  72. #include "timer.h"
  73.  
  74. /*
  75.     long timerset (t)
  76.     unsigned int t;
  77.   
  78.     This routine returns a timer variable based on the MS-DOS
  79.     time.  The variable returned is a long which corresponds to
  80.     the MS-DOS time at which the timer will expire.  The variable
  81.     need never be used once set, but to find if the timer has in
  82.     fact expired, it will be necessary to call the timeup function.
  83.     The expire time 't' is in hundredths of a second.
  84.   
  85.     Note: This routine as coded had a granularity of one week. I
  86.     have put the code that implements that inside the flag 
  87.     "HIGH_OVERHEAD". If you want it, go ahead and use it. For
  88.     BT's purposes, (minute) granularity should suffice.
  89.   
  90. */
  91. long timerset (t)
  92. unsigned int t;
  93. {
  94.    long l;
  95.  
  96. #ifdef HIGH_OVERHEAD
  97.    int l2;
  98.  
  99. #endif
  100.    int hours, mins, secs, ths;
  101.  
  102. #ifdef HIGH_OVERHEAD
  103.    extern int week_day ();
  104.  
  105. #endif
  106.  
  107.    /* Get the DOS time and day of week */
  108.    dostime (&hours, &mins, &secs, &ths);
  109.  
  110. #ifdef HIGH_OVERHEAD
  111.    l2 = week_day ();
  112. #endif
  113.  
  114.    /* Figure out the hundredths of a second so far this week */
  115.    l =
  116.  
  117. #ifdef HIGH_OVERHEAD
  118.       l2 * PER_DAY +
  119.       (hours % 24) * PER_HOUR +
  120. #endif
  121.       (mins % 60) * PER_MINUTE +
  122.       (secs % 60) * PER_SECOND +
  123.       ths;
  124.  
  125.    /* Add in the timer value */
  126.    l += t;
  127.  
  128.    /* Return the alarm off time */
  129.    return (l);
  130. }
  131.  
  132. /*
  133.     int timeup (t)
  134.     long t;
  135.   
  136.     This routine returns a 1 if the passed timer variable corresponds
  137.     to a timer which has expired, or 0 otherwise.
  138. */
  139. int timeup (t)
  140. long t;
  141. {
  142.    long l;
  143.  
  144.    /* Get current time in hundredths */
  145.    l = timerset (0);
  146.  
  147.    /* If current is less then set by more than max int, then adjust */
  148.    if (l < (t - 65536L))
  149.       {
  150. #ifdef HIGH_OVERHEAD
  151.       l += PER_WEEK;
  152. #else
  153.       l += PER_HOUR;
  154. #endif
  155.       }
  156.  
  157.    /* Return whether the current is greater than the timer variable */
  158.    return ((l - t) >= 0L);
  159. }
  160.  
  161.  
  162. /*
  163.     long addtime (t1, t2)
  164.     long t1;
  165.     unsigned int t2;
  166.   
  167.     This routine adds t2 hundredths of a second to the timer variable
  168.     in t1.  It returns a new timer variable.
  169.  
  170.         Not needed in BinkleyTerm, commented out.
  171.  
  172. long addtime (t1, t2)
  173. long t1;
  174. unsigned int t2;
  175. {
  176.    return (t1 + t2);
  177. }
  178. */
  179.